package com.itheima.stream03;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MapDemo {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list,"刘备字玄德","诸葛亮字孔明","曹操字孟德","孙权字仲谋","关羽字云长","张飞字翼德","赵云字子龙","乐进字文谦","李典字曼成","曹仁字子孝","曹洪字子廉");
        //使用Stream流完成 , 把名字收集到map集合中作为键,字号作为map集合的值
        list.stream()
                .collect(Collectors.toMap(
                        data -> data.split("字")[0]
                        , data -> data.split("字")[1]))
                .forEach((k,v)-> System.out.println(k+"字"+v));

    }
}
